home *** CD-ROM | disk | FTP | other *** search
/ Enter 2006 September / Enter 09 2006.iso / Internet / SpamExperts Home 1.1 / SpamExperts Home.exe / lib / spamexperts.modules / spamexperts / se_logging.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2006-07-14  |  1.8 KB  |  71 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4. '''
  5. Setup logging.
  6.  
  7. This is the very first thing that we do, so we maximise the chances of
  8. getting errors to the log file.  All that we require are that os and sys
  9. can be imported, which will only fail if the Python install is really
  10. stuffed (these are both actually built into Python).  If tempfile can
  11. also be imported (this should always be the case), then the temp
  12. directory is used as location; otherwise the current working directory
  13. is used.  If running in a console on Windows with pywin32 available, we
  14. leave output as-is.
  15.  
  16. This file must be kept as simple as possible, and should only include
  17. imports from the core Python distribution.  Imports are left as late
  18. as possible.
  19. '''
  20.  
  21. try:
  22.     import tempfile
  23. except ImportError:
  24.     log_dir = ''
  25.  
  26. log_dir = tempfile.gettempdir()
  27. _setup_complete = False
  28.  
  29. def setup(log_name = 'SpamExperts', rollover_count = 4):
  30.     global _setup_complete
  31.     if _setup_complete:
  32.         return None
  33.     
  34.     
  35.     try:
  36.         import win32api
  37.         win32api.GetConsoleTitle()
  38.     except:
  39.         import os
  40.         for i in range(rollover_count - 1, 0, -1):
  41.             
  42.             try:
  43.                 os.unlink(os.path.join(log_dir, '%s%d.log' % (log_name, i + 1)))
  44.             except os.error:
  45.                 pass
  46.  
  47.             
  48.             try:
  49.                 os.rename(os.path.join(log_dir, '%s%d.log' % (log_name, i)), os.path.join(log_dir, '%s%d.log' % (log_name, i + 1)))
  50.             continue
  51.             except os.error:
  52.                 continue
  53.             
  54.  
  55.         
  56.         import sys
  57.         stdout = sys.stdout
  58.         stderr = sys.stderr
  59.         sys.stdout = open(os.path.join(log_dir, '%s1.log' % (log_name,)), 'wt', 0)
  60.         sys.stderr = sys.stdout
  61.         
  62.         try:
  63.             stdout.seek(0)
  64.             print stdout.read()
  65.             stderr.seek(0)
  66.             print stderr.read()
  67.  
  68.  
  69.     _setup_complete = True
  70.  
  71.